﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using BudgetManager.Domain;
using Microsoft.Phone.Shell;
using System.Windows.Navigation;
using System.Windows.Controls.Primitives;
using System.Collections.ObjectModel;

namespace BudgetManager
{
    public partial class ManagementCategory : PhoneApplicationPage
    {
        ObservableCollection<Category> listBoxObservable;
        public ManagementCategory()
        {
            InitializeComponent();
            listBoxObservable = new ObservableCollection<Category>(Category.ReadAllCategoriesOrderByName());
            listBoxCategories.ItemsSource = listBoxObservable;
        }

 

        private void Ok_Click(object sender, EventArgs e)
        {
            if (txtBoxCategory.Text == "Click to add category" || txtBoxCategory.Text == "")
            {
                NavigationService.GoBack();
                return;
         }
            Category  cat = Category.addCategory(txtBoxCategory.Text);
            PhoneApplicationService.Current.State["Category"] = cat;
			listBoxObservable.Add(cat);
            NavigationService.GoBack();           
        }

        private void Delete_Click(object sender, EventArgs e)
        {
            object item = listBoxCategories.SelectedItem;
            if (item != null)
            {
                listBoxObservable.Remove(((Category)item));
                Category.DeleteCategory(((Category)item).Name);
                
            }
        }
		private void Cancel_Click(object sender, EventArgs e)
        {
			NavigationService.GoBack();          
        }

        private void clearText(object sender, System.Windows.Input.GestureEventArgs e)
        {
            txtBoxCategory.Text = String.Empty;
            //ApplicationBar.IsVisible = false;
        }
        private void Binding()
        {
           
           
        }
    }
}